home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / Libraries / Graphic Elements 3 / LibHdrs / Defs.h next >
Text File  |  1995-06-08  |  8KB  |  263 lines

  1. /*
  2.     Defs.h
  3.     
  4.     Type definitions for Graphic Elements release version 1.5b1
  5.     
  6.     Updated 5/25/95 for Graphic Elements version 3.0
  7.     
  8.     Copyright 1994 by Al Evans. All rights reserved.
  9.     
  10.     
  11. */
  12.  
  13. #ifndef GEDEFS
  14. #define GEDEFS
  15. //Get Toolbox symbols if we're compiling in MPW
  16. #ifdef applec
  17. #ifndef __cplusplus
  18. #ifndef PRELOAD
  19. #pragma load "::ToolKit.precompile"
  20. #define PRELOAD
  21. #endif
  22. #endif
  23. #endif
  24.  
  25. #ifndef __QDOFFSCREEN__
  26. #include <QDOffscreen.h>
  27. #endif
  28.  
  29. #ifndef __TIMER__
  30. #include <Timer.h>
  31. #endif
  32.  
  33. //Are we using the new headers?
  34. #if defined(__CONDITIONALMACROS__)
  35. #define NEWHEADERS 1
  36. #else
  37. #define NEWHEADERS 0
  38. #endif
  39.  
  40. //Is this for the PowerMac?
  41. #if (defined(powerc) || defined(__powerc))
  42. #define FORPPC 1
  43. #else
  44. #define FORPPC 0
  45. #endif
  46.  
  47. #include "List.h"
  48.  
  49. //All offscreen graphics are presently 8 bits deep
  50. #define    offscrnDepth    8
  51.  
  52. //Some forward declarations
  53. typedef struct GrafElement *GrafElPtr;
  54. typedef struct GEWorld *GEWorldPtr;
  55.  
  56. //Built-in directions
  57. typedef enum {none, up, left, down, right, upLeft, upRight, downLeft, downRight} GEDirection;
  58.  
  59. //Constant for "same-size" worlds
  60. #define scaleOneToOne 0x00010000
  61.  
  62. /* 
  63.     Prototype of function to initialize a graphic element from a resource or series
  64.     of resources. This function is responsible for creating an offscreen GWorld
  65.     for the element if required, and rendering the resource(s) into it.
  66.     
  67.     This function is responsible for setting the fields element->resID, element->graphRect,
  68.     and element->graphWorld.
  69. */
  70.  
  71. typedef pascal Boolean (*GraphicLoadFunc) (GEWorldPtr world, GrafElPtr element,
  72.                             short startResNum, short nResources);
  73.  
  74. /*
  75.     Prototype of function which, if present, will be called every time world is
  76.     updated, after drawing is complete. Can be used to automate other services
  77.     which need frequent time slices, such as sound maintenance procedures.
  78. */
  79.  
  80. typedef pascal void (*FramePostProcFunc) (GEWorldPtr world, Ptr data);
  81.  
  82. /*
  83.     Prototype for general-purpose bit copy function type-compatible with CopyBits.
  84.     BitCopyProcs are normally used for offscreen-to-offscreen copying only.
  85.     NOTE THAT THE PARAMETER maskRgn IS ALMOST NEVER A MASK REGION!  It is passed
  86.     from the drawData field of the graphic record. It should normally be nil, but
  87.     can be used for data required by a specific custom bitcopying procedure.
  88.     
  89.     If the "real" CopyBits is used directly for offscreen-to-offscreen drawing, care must be
  90.     taken that this field is nil or contains a real region handle.
  91. */
  92.  
  93. typedef pascal void (*BitCopyProc) (const BitMap *srcBits,const BitMap *dstBits,const Rect *srcRect,
  94.     const Rect *dstRect, short mode, RgnHandle maskRgn);
  95.     
  96. /*
  97.     Prototype for autochange procedure, which periodically moves graphic,
  98.     changes frames, scrolls graphic, etc.
  99. */
  100.  
  101. typedef pascal void (*AutoChangeProc) (GEWorldPtr world, GrafElPtr element);
  102.  
  103. /*
  104.     Prototype for interact procedure, which handles collisions
  105. */
  106.  
  107. typedef enum {collisionBegin, collisionContinue, collisionEnd} CollisionPhase;
  108.  
  109. typedef pascal void (*CollisionProc)(GEWorldPtr world, GrafElPtr element, 
  110.                             GEDirection dir, CollisionPhase phase, GrafElPtr hitElement);
  111.     
  112. /*
  113.     Prototype for rendering procedure to draw element into offscreen "stage" world
  114. */
  115.  
  116. typedef pascal void (*RenderProc)(GrafElPtr element, GWorldPtr destGWorld);
  117.  
  118. /*
  119.     Prototype for sensor-tracking procedure, called when mouse button is pressed
  120.     in a graphic element with sensor properties
  121. */
  122.  
  123. typedef pascal Boolean (*SensorTrack)(GEWorldPtr world, GrafElPtr sensor);
  124.  
  125. /*
  126.     Prototype for action procedure to be called by sensor
  127. */
  128.  
  129. typedef pascal void (*SensorAction)(GEWorldPtr world, GrafElPtr sensor, short sensorState);
  130.  
  131. /*
  132.     Prototype for "custom" dispose procedure, called when Graphic Element is 
  133.     disposed to give element a chance to free up any memory it has allocated.
  134. */
  135.  
  136. typedef pascal void (*CleanupProc)(GEWorldPtr world, GrafElPtr element);
  137.  
  138. /*
  139.     Defined values for flags field of Graphic Element. Bits 5-13 are reserved
  140.     for future system use, bits 16-31 are available for use in defining
  141.     custom Graphic Elements.
  142. */
  143.  
  144. enum {    geShown =        0x00000001L,
  145.         geChanged =        0x00000002L,
  146.         geHit =            0x00000004L,
  147.         geSensor =        0x00000008L,
  148.         geForward =        0x00000010L,
  149.         geMirrored =    0x00004000L,
  150.         geInverted =    0x00008000L
  151.     };
  152.     
  153. /*
  154.     The structure of an entry in a world's sensorList
  155. */
  156.  
  157. typedef struct SensorListEntry *SListEntryPtr;
  158.  
  159. typedef struct SensorListEntry {
  160.     SListEntryPtr    nextEntry;
  161.     Rect            sensorRect;
  162.     OSType            sensorID;
  163. } SensorListEntry;
  164.  
  165. /*
  166.     The variable-rate timer for a GEWorld
  167. */
  168.  
  169. //Timer "rate" for 1 ms world time/ms real time
  170. #define geTimerStdRate 0x00010000
  171.  
  172. typedef struct {
  173.     TMTask            aTMTask;
  174.     unsigned long    currentTime;
  175.     long             currentRate;
  176.     long            timeAccum;
  177.     Boolean            running;
  178. } GETMgrRec, *GETMgrRecPtr;
  179.  
  180.  
  181.     
  182. /*
  183.     A basic Graphic Element
  184. */
  185.  
  186. typedef struct GrafElement{
  187.  
  188.     //Bookkeeping and access
  189.     GrafElPtr        nextByPlane;        //Link in world's drawList
  190.     GrafElPtr        nextByID;            //Link in world's idList
  191.     GrafElPtr        masterGrafEl;        //Master (if any) controls movement of this GrafEl
  192.     GrafElPtr        slaveGrafEl;        //This GrafEl controls movement of slave (if any) 
  193.     OSType            objectID;            //This element's "name"
  194.     short            drawPlane;            //"Level" of object, higher number == closer to front
  195.     short            resID;                //# of resource from which element was derived, if any
  196.     long            flags;                //See definitions above
  197.     CleanupProc        cleanupProc;        //Custom dispose procedure, if any
  198.     
  199.     //Basic graphics data
  200.     GWorldPtr        graphWorld;            //Ptr to offscreen graphic, if any
  201.     Rect            graphRect;            //Source rectangle used by RenderProc
  202.     Rect            animationRect;        //Total dest rectangle, GEWorld coordinates
  203.     RenderProc        renderIt;            //Element's rendering procedure
  204.     BitCopyProc        drawIt;                //Lowlevel bit copier, if any
  205.     Ptr                drawData;            //Data passed to drawIt, if any
  206.     Rect            drawRect;            //Rect to update on this cycle
  207.     short            copyMode;            //Bit transfer mode
  208.  
  209.     //For automatic periodic changes
  210.     short            changeIntrvl;        //Interval between automatic changes
  211.     unsigned long    lastChangeTime;        //Last time autochange proc was called
  212.     AutoChangeProc    changeIt;            //Function for automatic changes
  213.     Ptr                changeData;            //Extra data for automatic changes
  214.     
  215.     //For collisions
  216.     CollisionProc    doCollision;        //Proc called when element collides
  217.     short            collisionPlane;        //Collides only with elements on this plane
  218.     GrafElPtr        collideElement;        //Other element involved in this collision
  219.     
  220.     //For direct user interactions
  221.     short            sensorType;            //Used to distinguish variant types
  222.     SensorTrack        trackingProc;        //Called when mousedown in sensor's rectangle
  223.     SensorAction    actionProc;            //Called by trackingProc when sensor is "activated"
  224.     short            sensorState;        //For whatever a sensor needs to save across calls
  225. } GrafElement;
  226.     
  227. /*
  228.     A world of Graphic Elements
  229. */
  230.  
  231. typedef struct GEWorld {
  232.  
  233.     //Objects maintained by this world
  234.     GrafElPtr            drawList;        //Head of linked list of GrafElements in draw order
  235.     GrafElPtr            idList;            //Head of linked list of GrafElements by ID
  236.  
  237.     //Graphic environment of this world
  238.     GrafPtr                gEWPort;        //Onscreen GrafPort for this world
  239.     GDHandle            portGDevice;    //Device for this port
  240.     GWorldPtr            stageGWorld;    //Offscreen construction "stage" for this world
  241.     Rect                animationRect;    //Total dest rect of this world
  242.     CTabHandle            worldCTable;    //Offscreen color table, should == onscreen cTable
  243.     Point                worldFocus;        //Offset of world from gEWPort top left
  244.     Fixed                worldScale;        //Ratio of screen pixels to world pixels
  245.     
  246.     //Current state of this world
  247.     GraphicLoadFunc        defaultLoader;    //Loader used if no other is specified
  248.     FramePostProcFunc    postProcFunc;    //Called after every update
  249.     Ptr                    userData;        //Extra world data (passed to postProcFunc)
  250.     LHeaderPtr            activeRectList;    //Two lists of update rects, so that animation and
  251.     LHeaderPtr            safeRectList;    //screen updating can be concurrent
  252.     LHeaderPtr            sensorList;        //Sensors in this world, see Sensors.h
  253.     RgnHandle            clipRgn;        //Clip region for this world
  254.     GETMgrRec            worldTime;        //Timer record for this world
  255.     unsigned long        lastFrameTime;    //last time screen was updated
  256.     short                msPerFrame;        //minimum "projection" interval, ms
  257.     Boolean                active;            //True if this animation is running
  258.     Boolean                changed;        //True if at least 1 object needs drawing
  259.     Boolean                onWorldList;    //True if GEWorldManager in use for this world
  260.     
  261. } GEWorld;
  262.  
  263. #endif